<?php

	if(isset($_GET['lid']))
	{
	  	$lid = intval($_GET['lid']);
	  	if($lid<=0)
	  	{
	  		edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	  	}
	}
	else
	{
		edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	}
	
	$logid=GetLoginUserID(); 
	$errmsg = GetMessageStack();
	$listDAO = GetListDAO();
	$userDAO = GetUserDAO();
		
	$listSummary = $listDAO->GetUserListSummary($lid);//($uid, $lid);
	
	if(!$listSummary)
	{
		edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	}
	
	if(isset($_POST['action']))
		$action = $_POST['action'];
	else
		$action='';	

	$responseContent = '';
	if( $action=='addResponse' )
	{	
		AddResponse();
	}
	
	ShowPage();
	
	
	function ShowPage()
	{
		global $listDAO,$lid,$listSummary;
		 
		if(!$listSummary){
		   	
		   die('page not found');
		   	
		}else{   
		
	//	   $i = rand(1,3);
	//	   if(intval($i)==1){
		     $listDAO->UpdateListViewCount($lid);
	//	   }  
		} 	
	}
	
	function AddResponse(){
		
	    global $errmsg,$listDAO,$lid,$logid, $listSummary, $responseContent;
	     
	
	     if($logid){
	     	      
	     	$vcode = edp_db_input(trim($_POST['vcode']));	
	     	
	     	$userid = $logid;
	     	$userip = getUserRealIPAddr();    
	     	$anonymous = edp_db_input(trim($_POST['post_author_type']));	

		    $response = edp_db_input(trim($_POST['response']));
	     	$responseContent = trim($_POST['response']);
	     	
	     	if( $vcode != edp_getsession( 'vcode' ) ){
			    $errmsg->add( 'reg', '验证码无效' );
			    return;
	    	} 
	    		 
	     	if( edp_is_empty_string($anonymous) || ($anonymous != '0' && $anonymous!='1') ){
		      $errmsg->add( 'reg', '无效的回应' );
		       return;
	        } 	
	     	
	  
	
//	     	$vcode = edp_db_input(trim($_POST['vcode']));	
//	     	if( $vcode != edp_getsession( 'vcode' ) ){
//			    $errmsg->add( 'reg', '验证码无效' );
//			    return;
//	    	} 
//	    	     	
//	     	$userid='0';
//	     	$userip = getUserRealIPAddr();
//	     	$anonymous = '1';	
	     
	     
		        
		     if( edp_is_empty_string($response) ||strlen($response)>1000){
			    $errmsg->add( 'reg', '回应不能为空或者超过1000字!' );
			    return;
		     }      
	     
		     $res=$listDAO->AddEntryResponse($lid, $listSummary['user_id'],$userid,$userip,$anonymous,$response);
		
		     if($res=='0')
			 {
				$errmsg->add( 'reg', '您在评单创建者的黑名单中，无法添加回应!' );
				return;
			 } 
			 if($res=='-1')
			 {
			    $errmsg->add( 'reg', '无效回应!' );
				return;
			 }   
			 
			 $responseContent = '';
	     }else{

	     	    $errmsg->add( 'reg', '无效回应!' );
				return;
	     }
	}


?>